<?php

    session_start();
    if($_SESSION['uid']==""||$_SESSION['level']!=4){
        header("Location: ../exit.php");
        exit;
    }
    include('/tool/submitValidate.php');
    include('/tool/pdo.php');
    include('/class/admin-role.class.php');
    include('/bll/AdminRoleBLL.php');
    include('/bll/PublicDataBLL.php');
    include('/class/public-data.class.php');

    $action = isset($_POST['action']) ? $_POST['action'] : 0;
    $data = isset($_POST['data']) ? $_POST['data'] : "";

    $message=array();

    switch((int)$action){
        //添加用户
        case 1:
            $dataObject=json_decode($data);
            $adminRoleBLL=new AdminRoleBLL();
            if($dataObject!=null){
                $message=$adminRoleBLL->addUser($dataObject);
            }
            break;
        //修改用户信息
        case 2:
            $dataObject=json_decode($data);
            $adminRoleBLL=new AdminRoleBLL();
            if($dataObject!=null){
                $message=$adminRoleBLL->updateUserInformation($dataObject);
            }
            break;
        //删除用户
        case 3:
            $dataObject=json_decode($data);
            $adminRoleBLL=new AdminRoleBLL();
            if($dataObject!=null){
                $message=$adminRoleBLL->deleteUser($dataObject);
            }
            break;
        case 4:
            $adminRoleBLL=new AdminRoleBLL();
            $message=$adminRoleBLL->getInitialList();
            break;
        default:break;
    }

    echo json_encode($message,JSON_UNESCAPED_UNICODE);
?>